package com.frinder.robot.handler;

import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import com.frinder.base.akka.BaseActor;
import com.google.common.collect.Lists;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @ClassName RobotActor
 * @Description 机器人管理器
 * @Author frinder
 * @Date 2019/9/30 14:16
 * @Verion 1.0
 */
@Component
@Scope("prototype")
public class RobotManagerActor extends BaseActor {

    public static final String NAME = "robot-manager-actor";

    private ActorSelection robotTaskManagerActor;

    @Override
    public void preStart() throws Exception {
        super.preStart();
        this.robotTaskManagerActor = actors.getActorSelection(RobotTaskManagerActor.NAME);
        Lists.newArrayList("R001", "R002")
                .forEach(o -> {
                    ActorRef ref = actors.getActorRef("robotActor",
                            String.format(RobotActor.NAME, o),
                            this.robotTaskManagerActor,
                            o
                    );
                    getContext().watch(ref);
                });
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .build();
    }

}
